package com.aaron.gesturehelper;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class MyConfiguration {
	public static final String ENABLE = "enabled";
	public static final String GESTURE = "gesture";
	public static final String VIBRATE = "vibrate";
	public static final String ABOUT = "about";
	public static final String ROOTED = "rooted";
	public static final String GESTUREAREA_COLOR = "gestureareacolor";
	public static final String GESTURE_COLOR = "gesturecolor";
	public static final String GESTUREAREA_EXPAND_TIME = "expandtime";
	public static final String TIPS = "tips";
	
	private SharedPreferences mPreferences;
	private static MyConfiguration sConfig;
	
	public static synchronized MyConfiguration getInstance(Context context) {
		if(sConfig == null) {
			sConfig = new MyConfiguration(context.getApplicationContext());
		}
		return sConfig;
	}
	
	private MyConfiguration(Context context) {
		mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
	}
	
	public boolean getBoolean(String key, boolean defValue) {
		return mPreferences.getBoolean(key, defValue);
	}

	public void setBoolean(String key, boolean value) {
		Editor edit = mPreferences.edit();
		edit.putBoolean(key, value);
		edit.commit();
	}
	
	public int getHexInt(String key, String defValue) {
		String str = mPreferences.getString(key, defValue);
		return Integer.parseInt(str,16);
	}
	
	public void setHexInt(String key, String value) {
		Editor edit = mPreferences.edit();
		edit.putString(key, value);
		edit.commit();
	}
	
	public int getInt(String key, int defValue) {
		return mPreferences.getInt(key, defValue);
	}
}
